<template>
  <div style="">
    <Header :left="true" leftText="返回" title="手工加严填报"> </Header>

    <van-form :style="autoHeight" @submit="onSubmit">
      <van-field required readonly class="formstyle" style="font-weight: bold" name="picker" :value="item.valuepline"
        label="生产线选择" placeholder="点击选择产线" @click="showPickerpline = true" />
      <van-popup v-model="showPickerpline" position="bottom" v-if="this.item.showButton">
        <van-picker show-toolbar :columns="searchColumns" @confirm="onConfirmpline" @cancel="showPickerpline = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.plineName }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKey" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>

      <van-field required style="font-weight: bold" readonly class="formstyle" :value="valueformstyle" name="picker"
        label="加严原因" placeholder="点击选择加严原因" @click="showPickerformstyle = true" />
      <van-popup v-model="showPickerformstyle" position="bottom" v-if="this.item.showButton">
        <van-picker show-toolbar :columns="columnsformstyle" @confirm="onConfirmformstyle"
          @cancel="showPickerformstyle = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.formstylename }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
        left-icon="description">基本信息</NoticeBar>

      <van-field required style="font-weight: bold" readonly clickable class="formstyle" name="datetimePicker"
        :value="item.planworkdatetime" label="加严开始时间" placeholder="选择时间" @click="showPickerdatetime = true" />
      <van-popup v-model="showPickerdatetime" position="bottom" v-if="this.item.showButton">
        <van-datetime-picker type="datetime" @confirm="onConfirmdatetime" @cancel="showPickerdatetime = false"
          :min-date="minDate" :max-date="maxDate" :value="currentdate" />
      </van-popup>

      <van-field class="formstyle" required :readonly="!this.item.showButton" style="font-weight: bold"
        v-if="!this.item.showButton" :value="this.item.valueABCType" name="建议等级" label="建议等级" placeholder="输入建议等级" />

      <!-- <van-field required readonly class="formstyle" style="font-weight: bold" name="picker" :value="item.valuepPOrderID"
        label="生产订单" placeholder="点击选择生产订单" show-word-limit type="textarea" maxlength="150"
        @click="showPickerPOrderID = true" rows="2" autosize /> -->
      <van-popup v-model="showPickerPOrderID" position="bottom">
        <van-picker show-toolbar :columns="columnsPOrderIDND" @confirm="onConfirmPOrderID"
          @cancel="showPickerPOrderID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.POrderIDAndMaterialName }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>

      <van-field :readonly="!this.item.showButton" style="font-weight: bold" v-model="item.message" class="formstyle"
        rows="4" autosize label="加严说明" type="textarea" maxlength="150" placeholder="输入加严说明" show-word-limit />

        <!-- <van-field required readonly class="formstyle" style="font-weight: bold" name="picker" :value="item.AppearanceCheckRecord"
        label="外观检验记录" placeholder="选择外观检验记录" @click="showPickerWG = true" />
        <div style="margin: 16px" v-if="item.AppearanceCheckRecord!=0&&item.AppearanceCheckRecord!=''&&item.AppearanceCheckRecord!=null">
          <van-button color="" round block type="info" @click="getRecord" style="">查看外观检验不合格记录</van-button>
        </div> -->
     
      <van-popup v-model="showPickerWG" position="bottom" v-if="this.item.showButton">
        <van-picker show-toolbar :columns="WGlist2" @confirm="onConfirmWG" @cancel="showPickerWG = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.showP }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKeyWG" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>

  
     
      <div style="margin: 16px" v-if="this.item.showButton">
        <van-button color="#138087" round block type="info" native-type="submit" @click="submitsure">保存</van-button>
      </div>
    </van-form>
  </div>
</template>
  
<script>
import {
  Col,
  Row,
  Form,
  Cell,
  Icon,
  Field,
  NumberKeyboard,
  Image as VanImage,
  Picker,
  popup,
  SubmitBar,
  Button,
  Loading,
  Overlay,
  Dialog,
  Toast,
  NoticeBar,
  Tag,
  DatetimePicker,
  ImagePreview,
  CellGroup,
  Uploader,
  Cascader,
  Calendar,
  RadioGroup,
  Radio,
  Divider,
  Stepper,
  AddressList,
  Checkbox,
  CheckboxGroup,
} from "vant";

import "vue-easytable/libs/themes-base/index.css";
import { VTable } from "vue-easytable";
import { _httpClient as _httpClientApisie } from "@/libs/apisie";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { getToken, getBaseApiFrefix } from "@/libs/auth";
import Header from "@/components/header.vue";
import { storage } from "@/libs/utils";

Vue.use(Form);
Vue.use(Field);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Picker);
Vue.use(popup);
Vue.use(SubmitBar);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(Cascader);
Vue.use(Calendar);
Vue.use(Cell);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Divider);
Vue.use(Stepper);
Vue.use(Button);
Vue.use(AddressList);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);

export default {
  name: "tightfill",
  components: {
    Form,
    Row,
    Col,
    Button,
    Header,
    Form,
    Cell,
    Icon,
    Field,
    NumberKeyboard,
    Dialog,
    Toast,
    NoticeBar,
    Row,
    Tag,
    popup,
    DatetimePicker,
    ImagePreview,
    CellGroup,
    Uploader,
    Col,
    Calendar,
    Cascader,
    Picker,
    RadioGroup,
    Radio,
    Divider,
    Stepper,
    VTable,
    AddressList,
    Checkbox,
    CheckboxGroup,
  },
  data() {
    return {
      searchKey: "",
      searchKey1: "",
      searchColumns: [],
      columnsPOrderIDND:[],
      showPickerPOrderID: false,
      valuepPOrderID: "",
      columnsPOrderID: [],
      valueplineid: "",
      itemsOne1: "",
      valueformstyleid: "",
      user: [],
      planworkdatetime: "",
      pOrderID: "",
      message: "",
      minDate: new Date(2023, 1, 1),
      maxDate: new Date(2025, 10, 1),
      currentdate: new Date(),
      nowDate: null,
      nowtimer: "",
      valuepline: "",
      showPickerpline: false,
      showPickerdatetime: false,
      form: {},
      item: {
        // planworkdatetime:this.getNowTime()
      },
      columnspline: [],
      columnsPLineID: [],
      valueformstyle: "",
      showPickerformstyle: false,
      columnsABCType: [
        { ABCType: "1", ABCTypeName: "甲" },
        { ABCType: "2", ABCTypeName: "乙" },
        { ABCType: "3", ABCTypeName: "丙" },
        { ABCType: "4", ABCTypeName: "-未确定" },
      ],
      columnsformstyle: [
        { formstyleid: "SM04", formstylename: "生产条件异常加严" },
        { formstyleid: "SM03", formstylename: "质量异常加严" },
        { formstyleid: "SM02", formstylename: "机器设备异常加严" },
        { formstyleid: "SM01", formstylename: "关键工艺参数异常加严" },
      ],
      fromData: {},
      showButton: false,

      //外观检验记录
      showPickerWG:false,
      WGlist:[],
      WGlist2:[],
      searchKeyWG:"",

      //实验室检验记录
      showPickerSYS:false,
      SYSlist:[],
      SYSlist2:[],
      searchKeySYS:"",
    };
  },
  created: function () {
    this.user = JSON.parse(storage.get("user"));
    this.user.userId = this.user.userName;
    api.requestPermission(
      {
        list: ["camera", "microphone", "storage"],
      },
      function (ret, err) { }
    );

    // try {
    //   var manageStorage = api.require('manageStorage');
    //   manageStorage.requestAllFilePermission({
    //   }, function (ret) {
    //     // api.alert({
    //     //   msg: JSON.stringify(ret)
    //     // })
    //   });
    // } catch {

    // }
    
    this.getPline();
    this.getPOrderID();
    this.getWGList();

   
    if (typeof api.pageParam.itemQuery != "undefined") {
     
      this.itemQuery = api.pageParam.itemQuery;

      if(this.itemQuery.showButton==false){
          this.init(this.itemQuery.Id);
      }
    
      this.item.valuepline = this.itemQuery.valuePLineID;
      this.item.valueplineid = this.itemQuery.PLineID;
      this.item.showButton = this.itemQuery.showButton;
      this.valueformstyle = this.itemQuery.valueAddStrictType;
      this.item.valueformstyleid = this.itemQuery.StrictTypeID;
      this.item.planworkdatetime = this.itemQuery.FromDatetime;
      this.item.valuepPOrderID = this.itemQuery.valuepPOrderID;
      this.item.pOrderID = this.itemQuery.POrderID;
      this.item.message = this.itemQuery.StrictDescription;
      this.item.Id = this.itemQuery.Id;
      this.item.valueABCType = this.itemQuery.valueABCType;
      // if (this.itemQuery.isOpen) {
      //   this.showScanner();
      // }
    }
    if (typeof api.pageParam.item != "undefined") {
      // this.item = api.pageParam.item;
      this.valueformstyle = this.showFormstyle(this.item.valueformstyleid);
    }
    if (typeof api.pageParam.form != "undefined") {
      this.form = api.pageParam.form;
    }
    if (typeof this.form.POrderID != "undefined") {
      this.item.pOrderID = this.form.POrderID;
    }
    if(this.itemQuery.showButton==true){
      this.item.planworkdatetime = this.getNowTime();
    }
    
  },
  mounted() { },
  watch: {  //实时监听搜索输入内容
    'searchKey': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.searchColumns = this.columnspline.filter(item => item.plineName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    },
    'searchKey1': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.columnsPOrderIDND = this.columnsPOrderID.filter(item => item.POrderIDAndMaterialName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    },

    'searchKeyWG':{
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.WGlist2 = this.WGlist.filter(item => item.showP.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,

    },
    'searchKeySYS':{
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.SYSlist2 = this.SYSlist.filter(item => item.showP.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,

    }
  },
  methods: {
    getNowTimeplus() {
      let dateTime
      let yy = new Date().getFullYear()
      let mm = new Date().getMonth() + 1
      let dd = new Date().getDate()
      let hh = new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes()
        :
        new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds()
        :
        new Date().getSeconds()
      dateTime = yy + '-' + mm + '-' + dd + ' ' + hh + ':' + mf + ':' + ss
      return dateTime
    },
    async sendmessage(id) {
      let _this = this;

      let eventDescription = "";
      let eventDatetime = _this.getNowTimeplus();
      let eventTypeID = "N3";
      let eventID = "";
      let messageContent = "";
      let msgContentTypeID = "";
      let pLineID = "";
      let machineID = "";
      let pShiftID = "";
      let teamID = "";
      let pOrderID = "";
      let productionBarcode = "";
      let materialBarcode = "";
      let relatedEmployee = "";
      let messageStatus = "";
      let processBatchID = "";
      let beginDatetime = _this.getNowTimeplus();
      let sendFinished = false;
      let closed = false;

      msgContentTypeID = "ADS01";
      eventID = "ADS01";
      eventDescription = "加严管控记录:" + id + "已创建，请品管主任尽快判定等级！";
      messageContent = "加严管控记录:" + id + "已创建，请品管主任尽快判定等级！";


      let bodysss = {
        eventDescription: eventDescription,
        eventDatetime: eventDatetime,
        eventTypeID: eventTypeID,
        eventID: eventID,
        messageContent: messageContent,
        msgContentTypeID: msgContentTypeID,
        factoryID: "TC00",
        pLineID: pLineID,
        machineID: machineID,
        pShiftID: pShiftID,
        teamID: teamID,
        pOrderID: pOrderID,
        productionBarcode: productionBarcode,
        materialBarcode: materialBarcode,
        relatedEmployee: relatedEmployee,
        messageStatus: messageStatus,
        processBatchID: processBatchID,
        beginDatetime: beginDatetime,
        sendFinished: sendFinished,
        closed: closed
      };
      try {
        let res = await _httpClientApisie.post(
          _httpClientApisie.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
          {
            body: bodysss,
          }
        );
        //alert(JSON.stringify(res));
        if (res.Message == null) {
          Toast.clear();
          Toast.success("发送成功");
          api.openWin({
            name: "tightfill",
            url: "./tightenup-queryTightfill.html",
            reload: true,
          });
          setTimeout(function () {
            _this.$ac.closeWin();
          }, 2000);

        } else {
          Toast.clear();
          Toast.fail("发送失败");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    getNowTime() {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf;
      return dateTime;
    },
    onConfirmPOrderID(value, index) {
      this.item.valuepPOrderID =
        this.columnsPOrderIDND[index].POrderIDAndMaterialName;
      this.item.pOrderID = this.columnsPOrderIDND[index].POrderID;
      this.showPickerPOrderID = false;
    },
    
    showABCTypeName(ABCType) {
      var ABCTypeName = ABCType;
      this.columnsABCType.forEach((item) => {
        if (item.ABCType === ABCType) {
          ABCTypeName = item.ABCTypeName;
        }
      });
      return ABCTypeName;
    },
    async getPOrderID() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/ProductionOrder/GetList"
        );

       
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            POrderID: item.POrderID,
            MaterialName: item.MaterialName,
            MaterialID: item.MaterailID,
            POrderIDAndMaterialName: item.POrderID + " " + item.MaterialName,
          }));
          _this.columnsPOrderID = teamMap;
          _this.columnsPOrderIDND = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    showPOrderIDName(POrderID) {
      var POrderIDName = POrderID;
      this.columnsPOrderID.forEach((item) => {
        if (item.POrderID === POrderID) {
          POrderIDName = item.POrderIDAndMaterialName;
        }
      });
      return POrderIDName;
    },
    //获取生产线
    showPLineIDName(plineId) {
      var plineName = plineId;
      this.columnspline.forEach((item) => {
        if (item.plineId == plineId) {
          plineName = item.plineName;
        }
      });
      return plineName;
    },
    showFormstyle(formstyleid) {
      var formstylename = formstyleid;
      this.columnsformstyle.forEach((item) => {
        if (item.formstyleid === formstyleid) {
          formstylename = item.formstylename;
        }
      });
      return formstylename;
    },
    async confirmmessage(item) {
      let _this = this;
      //Toast.fail(JSON.parse(something))
      api.openWin({
        name: "queryTightfill",
        url: "./tightenup-queryTightfill.html",
        reload: true,
        pageParam: {
          item: item,
          form: {},
        },
      });
      setTimeout(function () {
        _this.$ac.closeWin();
      }, 1000);
    },
    async submitsure() {
      let _this = this;
      Toast.loading({
        mask: true,
        forbidClick: true,
        duration: 0,
        message: "请稍等...",
      });
      let bodyss = {
        factoryID: "TC00",
        abcType: "4",
        strictDescription: _this.item.message,
        required: "",
        memo: "",
        strictTypeID: _this.item.valueformstyleid,
        pLineID: _this.item.valueplineid,
        pOrderID: _this.item.pOrderID,
        fromDatetime: _this.item.planworkdatetime,
        creator: _this.user.userId,
        createDatetime: _this.currentdate,
        modifytor: "",
        modifyDatetime: _this.currentdate,
        systemCreated: false,
        comfirmed: false,
        comfirmDatetime: "1970-01-01 00:00:00.000",
        comfirmMan: "",
        comfirmMemo: "",
        checked: false,
        checkeDatetime: "1970-01-01 00:00:00.000",
        checkeMan: "",
        checkeMemo: "",
        closed: false,
        closeMan: "",
        closeDatetime: "1970-01-01 00:00:00.000",
        closeMemo: "",
        received: false,
        receiveDatetime: "1970-01-01 00:00:00.000",
        receiveMan: "",
        receiveMemo: "",
        id: _this.item.Id,
        LaboratoryCheckRecordName:_this.item.LaboratoryCheckRecordName,
        LaboratoryCheckRecord:_this.item.LaboratoryCheckRecord,
        AppearanceCheckRecordName:_this.item.AppearanceCheckRecordName,
        AppearanceCheckRecord:_this.item.AppearanceCheckRecord,
        token: "",
      };
      //alert(JSON.stringify(bodyss));
      try {
        let res = await _httpClientApisie.post(
          _httpClientApisie.getApiPrefix() + "/AddStrictManage/SaveEntity",
          {
            body: bodyss,
          }
        );
        //alert(JSON.stringify(res));
        if (res.HttpCode === "200") {
          Toast.clear();
          Toast.success("保存成功");
          _this.sendmessage(res.Data);
          //alert(JSON.stringify(res))
        } else {
          Toast.clear();
          Toast.fail("保存失败");
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    onConfirmdatetime(time) {
      this.tempTime = time;
      this.item.planworkdatetime = `${time.getFullYear()}-${time.getMonth() + 1
        }-${time.getDate()} ${time.getHours().toString().padStart(2, 0)}:${time
          .getMinutes()
          .toString()
          .padStart(2, 0)}`;
      this.showPickerdatetime = false;
    },
    async onConfirmpline(value, index) {

      let plineId=this.searchColumns[index].plineId

      try{
      //查询是否已经加严
      ///AddStrictManage/GetList
      let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/AddStrictManage/GetList?PLineID="+plineId+"&Closed=false&Actived=true"
        );
      if(res.HttpCode==="200"){
        if(res.Data.length!=0){
          Dialog.confirm({
              title: '加严提示',
              message: '本产线已加严，是否再次加严',
            }).then(()=>{}).catch(() => {
              
              setTimeout(()=>{
                this.$ac.closeWin();
              }, 500);
              
            });
        }

      }
    }catch(e){
      Toast.fail(e)
    }

      this.item.valuepline = value;
      this.item.valueplineid = this.searchColumns[index].plineId;
      this.item.valuepline = this.searchColumns[index].plineName;
      this.showPickerpline = false;
    },
    onConfirmformstyle(value, index) {
      this.valueformstyle = value;
      this.item.valueformstyleid = this.columnsformstyle[index].formstyleid;
      this.valueformstyle = this.columnsformstyle[index].formstylename;
      //alert(this.columnsformstyle[index].formstyleName);
      this.showPickerformstyle = false;
    },
    clear() {
      this.message = "";
      this.pOrderID = "";
    },
    async getPline() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/PLineEquipment/GetList?FactoryID=TC00"
        );
        if (res.HttpCode === "200") {
          //alert(JSON.stringify(res));
          let teamMap = res.Data.map((item) => ({
            plineId: item.PLineID,
            plineName: item.PLineName,
          }));
          _this.columnspline = teamMap;
          _this.searchColumns =teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async getMachineIDByPOrderIDFromMachineCurrentPOrder(POrderID) {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/MachineCurrentPOrder/GetList?POrderID=" +
          POrderID
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            plineId: item.MachineID,
            plineName: _this.showPLineIDName(item.MachineID),
          }));
          _this.columnspline = teamMap;
          this.$forceUpdate();
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async getPOrderIDByMachineIDFromMachineCurrentPOrder(MachineID) {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/MachineCurrentPOrder/GetList?MachineID=" +
          MachineID
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            POrderID: item.POrderID,
            MaterialName: item.MaterailName,
            MaterialID: item.MaterailID,
            POrderIDAndMaterialName: item.POrderID + " " + item.MaterailName,
          }));
          _this.columnsPOrderID = teamMap;
          this.$forceUpdate();
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async getOrderingInformation() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/ProductionOrder/GetList"
        );
        if (res.HttpCode === "200") {
          _this.itemsOne1 = res.Data;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    async getWGList(){
        //QualityAppearanceCheck/GetPageListJson
        let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/QualityAppearanceCheck/GetList"
        );
        if (res.HttpCode === "200") {
          
          let teamMap = res.Data.map((item) => ({
            Id: item.Id,
            showP: item.Id+" "+item.MaterialName,
          }));
          _this.WGlist = teamMap;
          _this.WGlist2 =teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }

    },
    onConfirmWG(value, index){
      
      this.item.AppearanceCheckRecord = this.WGlist2[index].Id;
      this.item.AppearanceCheckRecordName = this.WGlist2[index].showP;
      this.showPickerWG = false;
    },

    async getSYSList(){
        //QualityAppearanceCheck/GetPageListJson
        let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/QualityCheckRecord/GetList"
        );
        if (res.HttpCode === "200") {
          
          let teamMap = res.Data.map((item) => ({
            Id: item.Id,
            showP: item.Id+" "+item.SheetName,
          }));
          _this.SYSlist = teamMap;
          _this.SYSlist2 =teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }

    },
    onConfirmSYS(value, index){
      
      this.item.LaboratoryCheckRecord = this.SYSlist2[index].Id;
      this.item.LaboratoryCheckRecordName = this.SYSlist2[index].showP;
      this.showPickerSYS = false;
    },
    async checkSYS(){
      let id=this.item.LaboratoryCheckRecord

      if(id==""||id==null || id==undefined){
        Toast.clear()
        Toast.fail("当前没有维护实验室检验记录，无法获取不合格记录！")
        return
      }


      //QualityCheckRecord/GetQualityCheckDisqualifiedMsg?CheckRecordID=609416630832730112

      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/QualityCheckRecord/GetQualityCheckDisqualifiedMsg?CheckRecordID="+id
        );
        if (res.HttpCode === "200") {
          alert(res.Data)
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    async init(id){
      try {

        let rest =await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/AddStrictManage/GetEntity?id="+id
        )
     

        if (rest.HttpCode === "200") {
          
          this.item.AppearanceCheckRecord=rest.Data.AppearanceCheckRecord
          this.item.LaboratoryCheckRecord=rest.Data.LaboratoryCheckRecord
        }

        if(this.item.AppearanceCheckRecord!=null){
          let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/QualityAppearanceCheck/GetEntityName?FieldValue="+this.item.AppearanceCheckRecord
        );
          if (res.HttpCode === "200") {
            this.item.AppearanceCheckRecordName=this.item.AppearanceCheckRecord+" "+res.Data
          
          }
        }
        

        if(this.item.LaboratoryCheckRecord!=null){
          let res2 = await _httpClientApisie.get(
            _httpClientApisie.getApiPrefix() +
            "/QualityCheckRecord/GetEntityName??FieldValue="+this.item.LaboratoryCheckRecord
          );
          if (res2.HttpCode === "200") {
            this.item.LaboratoryCheckRecordName=this.item.LaboratoryCheckRecord+" "+res2.Data
        
          }
      }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    getRecord(){
      let id = this.item.AppearanceCheckRecord

        api.openWin({
          name: 'qCcheckReview',
          url: './quality-qCcheckReview.html',
          pageParam: {
              id: id
          }
      });

    }

    
  },
};
</script>
  
<style>

</style>
  